package snapex.invoice.service.impl;

import static org.mybatis.dynamic.sql.SqlBuilder.isIn;

import java.util.List;

import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.extern.slf4j.Slf4j;
import snapex.core.mapper.InvoiceImageDynamicSqlSupport;
import snapex.core.mapper.InvoiceImageMapper;
import snapex.core.model.InvoiceImage;
import snapex.invoice.service.IInvoiceService;

@Slf4j
@Service
@Transactional
public class InvoiceService implements IInvoiceService {
	
	@Autowired
	InvoiceImageMapper invoiceImageMapper;
		
	@Override
	public InvoiceImage getInvoiceImage(String invoiceId) {
		return invoiceImageMapper.selectByPrimaryKey(invoiceId);		
	}
	
	@Override
	public List<InvoiceImage> getInvoiceImages(List<String> invoiceIds){
		if(invoiceIds.isEmpty()) {
			return null;
		}
		
		return invoiceImageMapper.selectByExample().where(InvoiceImageDynamicSqlSupport.invoiceId, isIn(invoiceIds)).build().execute();
	}
	
	private String generateInvoideId() {
		return RandomStringUtils.randomAlphabetic(32);
	}
}
